package com.zlm.weather.config;

import com.zlm.weather.quartz.WeatherDataSyscJob;
import com.zlm.weather.util.ConfigProperties;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

/**
 * @Author: 郑
 * @Date: Create in 2020-1-18.
 */
//@Configuration
public class QuartzConfig {
    @Autowired
    private ConfigProperties configProperties;

    @Bean
    public JobDetail weatherSybcJobDetil(){
        return JobBuilder.newJob(WeatherDataSyscJob.class)
                .withIdentity("weatherDataSyscJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger weatherDataSyncTrigger(){
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInHours(Integer.valueOf(configProperties.getWeather_timeout()))
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(weatherSybcJobDetil())
                .withIdentity("weatherDataSyncTrigger")
                .withSchedule(simpleScheduleBuilder)
                .build();
    }
}
